#ifndef __his_stream_H__
#define __his_stream_H__

#pragma once

#include "MemStream.h"

//==============================================================================
// CHisStream

class CHisStream
{
public:
	CHisStream(unsigned int growSize = 1024);
	CHisStream(void* pBuffer, unsigned int bufferSize);
	virtual ~CHisStream();

public:
	unsigned int GetPosition() const { return m_stream.GetPosition(); }
	unsigned int Seek(int offset, int whence);
	unsigned int Read(void* pBuffer, unsigned int size);
	unsigned int Write(const void* pBuffer, unsigned int size);
	unsigned int GetSize() const;

	void Attach(void* pBuffer, unsigned int bufferSize);
	void* Detach();

	unsigned int Pick(void* pBuffer, unsigned int size);
	void SetSize(unsigned int newSize);
	void Abort();
	void Flush();
	void Close();
	void* GetBufferPtr() const { return m_stream.GetBufferPtr(); }
	unsigned int GetCapacity() const { return m_stream.GetCapacity(); }

	bool ReadInt8(int8_t* pDst);
	bool ReadUint8(uint8_t* pDst);
	bool ReadInt16(int16_t* pDst);
	bool ReadUint16(uint16_t* pDst);
	bool ReadInt32(int32_t* pDst);
	bool ReadUint32(uint32_t* pDst);
	bool ReadInt64(int64_t* pDst);
	bool ReadUint64(uint64_t* pDst);
	bool ReadSingle(float* pDst);
	bool ReadDouble(double* pDst);
	bool ReadSmallString(char* psz, int len);
	bool ReadShortString(char* psz, int len);
	bool ReadString(char* psz, int len);
// 	bool ReadSmallCString(CString& str);
// 	bool ReadShortCString(CString& str);
// 	bool ReadCString(CString& str);

	bool WriteInt8(int8_t src);
	bool WriteUint8(uint8_t src);
	bool WriteInt16(int16_t src);
	bool WriteUint16(uint16_t src);
	bool WriteInt32(int32_t src);
	bool WriteUint32(uint32_t src);
	bool WriteInt64(int64_t src);
	bool WriteUint64(uint64_t src);
	bool WriteSingle(float src);
	bool WriteDouble(double src);
	bool WriteSmallString(const char* psz, int len = -1);
	bool WriteShortString(const char* psz, int len = -1);
	bool WriteString(const char* psz, int len = -1);
// 	bool WriteSmallCString(const CString& str);
// 	bool WriteShortCString(const CString& str);
// 	bool WriteCString(const CString& str);

private:
	CMemStream m_stream;
};

#endif //__his_stream_H__
